#pragma once

#include <string>
#include "../util.hpp"

namespace pharmacy_server
{
    struct PurchaseOrder
    {
        using tuple_of_purchase_order = std::tuple<std::string, std::string, int, std::string>;

        PurchaseOrder(const std::string& medicine_name, const std::string& supplier, int quantity, const std::string& purchase_date)
            : medicine_name(medicine_name)
            , supplier(supplier)
            , quantity(quantity)
            , purchase_date(purchase_date)
        {
        }

        std::string medicine_name;
        std::string supplier;
        int quantity;
        std::string purchase_date;

        Json::Value to_json() const
        {
            Json::Value root;
            root["medicine_name"] = medicine_name;
            root["supplier"] = supplier;
            root["quantity"] = quantity;
            root["purchase_date"] = purchase_date;
            return root;
        }

        void from_json(const Json::Value& root)
        {
            medicine_name = root["medicine_name"].asInt();
            supplier = root["supplier"].asString();
            quantity = root["quantity"].asInt();
            purchase_date = root["purchase_date"].asString();
        }

        void from_tuple(const tuple_of_purchase_order& tuple)
        {
            medicine_name = std::get<0>(tuple);
            supplier = std::get<1>(tuple);
            quantity = std::get<2>(tuple);
            purchase_date = std::get<3>(tuple);
        }

        tuple_of_purchase_order to_tuple() const
        {
            return std::make_tuple(medicine_name, supplier, quantity, purchase_date);
        }

        static PurchaseOrder from_tuple_quickly(const tuple_of_purchase_order& tuple)
        {
            return PurchaseOrder(std::get<0>(tuple), std::get<1>(tuple), std::get<2>(tuple), std::get<3>(tuple));
        }
    };
}